import { createStore } from 'vuex'

const store = createStore({
  state: {
    isLoggedIn: false, // 用于表示用户是否登录
    userInfo: null // 可存储用户信息，如用户名等
  },
  mutations: {
    SET_LOGGED_IN(state, isLoggedIn) {
      state.isLoggedIn = isLoggedIn
    },
    SET_USER_INFO(state, userInfo) {
      state.userInfo = userInfo
    }
  },
  actions: {
    login({ commit }, userData) {
      // 这里假设调用登录接口获取数据
      // 实际应替换为真实的登录请求逻辑
      const response = {
        code: 200,
        data: { username: userData.username }
      }
      if (response.code === 200) {
        commit('SET_LOGGED_IN', true)
        commit('SET_USER_INFO', response.data)
      }
    }
  }
})

export default store